﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Student_management
{
    public partial class frmMain : Form
    {
        Connection db = new Connection();
        public static string username = "KIDWAR";
        public static string quyen = "admin";
        public static string lop = "10A1";
        public static string mon = "D1";
        public frmMain()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            foreach (Form frm in this.MdiChildren)
            {
                frm.Close();
            }
            frmTiepNhanHS form = new frmTiepNhanHS();
            form.MdiParent = this;
            form.Show();
        }

        private void Nhap_Click(object sender, EventArgs e)
        {
            foreach (Form frm in this.MdiChildren)
            {
                frm.Close();
            }
            frmDanhSachLop form = new frmDanhSachLop();
            form.MdiParent = this;
            form.Show();
        }

        private void quanly_Click(object sender, EventArgs e)
        {
            foreach (Form frm in this.MdiChildren)
            {
                frm.Close();
            }
            frmTraCuuHS form = new frmTraCuuHS();
            form.MdiParent = this;
            form.Show();
        }

        void enable()
        {
            if (quyen == "admin")
            {
                quảnLýAcountToolStripMenuItem.Enabled = true;
                tiếpNhậnHọcsinhToolStripMenuItem.Enabled = true;
                button1.Enabled = true;
                nhậpBảngĐiểmMônToolStripMenuItem.Enabled = true;
                button3.Enabled = true;
                thayĐổiQuyĐịnhToolStripMenuItem.Enabled = true;
                button2.Enabled = true;
                thayĐổiThôngTinTrườngToolStripMenuItem.Enabled = true;
            }
            else
                if (quyen == "gv")
                {
                    if(lop != "")
                    {
                        tiếpNhậnHọcsinhToolStripMenuItem.Enabled = true;
                        button1.Enabled = true;
                    }
                    if (mon != "")
                    {
                        nhậpBảngĐiểmMônToolStripMenuItem.Enabled = true;
                        button3.Enabled = true;
                    }
                }
            user.Text = "Người đăng nhập: " + username;
        }
        private void button3_Click(object sender, EventArgs e)
        {
            foreach (Form frm in this.MdiChildren)
            {
                frm.Close();
            }
            frmBangDiemMon form = new frmBangDiemMon();
            form.MdiParent = this;
            form.Show();
        }

        private void help_Click(object sender, EventArgs e)
        {
            foreach (Form frm in this.MdiChildren)
            {
                frm.Close();
            }
            frmBCMon form = new frmBCMon();
            form.MdiParent = this;
            form.Show();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            foreach (Form frm in this.MdiChildren)
            {
                frm.Close();
            }
            frmBCHocKy form = new frmBCHocKy();
            form.MdiParent = this;
            form.Show();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            foreach (Form frm in this.MdiChildren)
            {
                frm.Close();
            }
            frmThayDoiQuyDinh form = new frmThayDoiQuyDinh();
            form.MdiParent = this;
            form.Show();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            label4.Text = System.DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss");
        }

        private void thayĐổiThôngTinTrườngToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmInfo form = new frmInfo();
            if (form.ShowDialog() == DialogResult.Cancel)
                update();
        }

        public void update()
        {
            DataTable a = new DataTable();
            a = db.getDS("Select * from ThongTin");
            truong.Text = a.Rows[0]["Ten"].ToString();
            sdt.Text = "SDT: " + a.Rows[0]["DT"].ToString();
            logo.ImageLocation = a.Rows[0]["logo"].ToString();
        }

        private void frmMain_Load(object sender, EventArgs e)
        {
            enable();
            update();
        }

        private void quảnLýAcountToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (Form frm in this.MdiChildren)
            {
                frm.Close();
            }
            frmAccount form = new frmAccount();
            form.MdiParent = this;
            form.Show();
        }

        private void frmMain_FormClosed(object sender, FormClosedEventArgs e)
        {
            Application.Exit();
        }

        private void đăngxuấtToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Bạn có chắc chắn muốn đăng xuất không ?", "Đăng xuất", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                this.Hide();
                frmLogin n = new frmLogin();
                n.Show();
            }
        }

        private void thoátToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Bạn có chắc chắn muốn thoát không ?", "Thoát", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                Application.Exit();
            }
        }

        private void đổimậtKhẩuToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmChangepass n = new frmChangepass();
            n.ShowDialog();
        }

        private void hướngdẫnToolStripMenuItem_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process proc = new System.Diagnostics.Process();
            proc.EnableRaisingEvents = false;
            proc.StartInfo.FileName = "help.pdf";
            proc.Start();
        }

        private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmAbout n = new frmAbout();
            n.ShowDialog();
        }
    }
}
